home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / ucrasm27.zip / SOURCE.ZIP / RMVLAST.ASM < prev    next >
Assembly Source File  |  1992-03-09  |  4KB  |  170 lines

  1.  
  2. ; Need to include "lists.a" in order to get list structure definition.
  3.  
  4.         include    lists.a
  5.  
  6.  
  7. wp        equ    <word ptr>        ;I'm a lazy typist
  8.  
  9.  
  10. ; Special case to handle MASM 6.0 vs. all other assemblers:
  11. ; If not MASM 5.1 or MASM 6.0, set the version to 5.00:
  12.  
  13.         ifndef    @version
  14. @version    equ    500
  15.         endif
  16.  
  17.  
  18.  
  19. StdGrp        group    stdlib,stddata
  20. stddata        segment    para public 'sldata'
  21. stddata        ends
  22.  
  23. stdlib        segment    para public 'slcode'
  24.         assume    cs:stdgrp
  25.  
  26. ; sl_RemovelAst -    ES:DI points at a list.
  27. ;            Removes the last item in the list and returns a
  28. ;            pointer to this item in DX:SI.  Returns the carry
  29. ;            flag set if the list was empty.
  30. ;
  31. ; Randall Hyde  3/3/92
  32. ;
  33.  
  34.         public    sl_RemoveLast
  35. sl_RemoveLast    proc    far
  36.         push    ds
  37.         push    es
  38.         push    di
  39.  
  40.         if    @version ge 600
  41.  
  42. ; MASM 6.0 version goes here
  43.  
  44.         cmp    wp es:[di].List.Tail+2, 0    ;Empty list?
  45.         jne    HasAList
  46.  
  47. ; At this point, the Tail pointer is zero.  This only occurs if the
  48. ; list is empty.
  49. ;
  50. ; Note: Technically, the NIL pointer is 32-bits of zero. However, this
  51. ; package assumes that if the segment is zero, the whole thing is zero.
  52. ; So don't put any nodes into segment zero!
  53.  
  54.         xor    dx, dx                ;Set DX:SI to NIL.
  55.         mov    si, dx
  56.         stc
  57.         jmp    RemoveDone
  58.  
  59. ; If the HEAD pointer is NON-NIL, grab the guy off the front of the
  60. ; list down here.
  61.  
  62. HasAList:    lds    si, es:[di].List.Tail          ;Get ptr to last
  63.  
  64. ; Remove the last node from the list by storing the address of the next to
  65. ; last node in TAIL and setting the NEXT field of that node to NIL.
  66. ; Check to see if the list becomes empty (because we'll need to adjust HEAD
  67. ; when that happens).
  68.  
  69.         mov    dx, wp ds:[si].Node.Prev
  70.         mov    wp es:[di].List.Tail, dx
  71.         mov    wp es:[di].List.CurrentNode, dx
  72.  
  73.         mov    dx, wp ds:[si].Node.Prev+2
  74.         mov    wp es:[di].List.Tail+2, dx
  75.         mov    wp es:[di].List.CurrentNode+2, dx
  76.  
  77.         or    dx, dx                ;List empty?
  78.         jz         LastGuy
  79.  
  80. ; If the list is not empty, we need to set the NEXT field of the new
  81. ; last node to NIL.
  82.  
  83.         les    di, es:[di].List.Tail
  84.         mov    wp es:[di].Node.Next, 0
  85.         mov    wp es:[di].Node.Next+2, 0
  86.         jmp    GoodRemove
  87.  
  88. ; If we just removed the last node from the list, set the head pointer
  89. ; to NIL (Tail is already NIL from above).
  90.  
  91.  
  92. LastGuy:    mov    wp es:[di].List.Head, dx
  93.         mov    wp es:[di].List.Head+2, dx
  94.  
  95.  
  96.  
  97.  
  98.  
  99.         else
  100.  
  101. ; Handle other assemblers down here
  102.  
  103.         cmp    wp es:[di].Tail+2, 0        ;Empty list?
  104.         jne    HasAList
  105.  
  106. ; At this point, the Tail pointer is zero.  This only occurs if the
  107. ; list is empty.
  108. ;
  109. ; Note: Technically, the NIL pointer is 32-bits of zero. However, this
  110. ; package assumes that if the segment is zero, the whole thing is zero.
  111. ; So don't put any nodes into segment zero!
  112.  
  113.         xor    dx, dx                ;Set DX:SI to NIL.
  114.         mov    si, dx
  115.         stc
  116.         jmp    RemoveDone
  117.  
  118. ; If the HEAD pointer is NON-NIL, grab the guy off the front of the
  119. ; list down here.
  120.  
  121. HasAList:    lds    si, es:[di].Tail          ;Get ptr to last
  122.  
  123. ; Remove the last node from the list by storing the address of the next to
  124. ; last node in TAIL and setting the NEXT field of that node to NIL.
  125. ; Check to see if the list becomes empty (because we'll need to adjust HEAD
  126. ; when that happens).
  127.  
  128.         mov    dx, wp ds:[si].Prev
  129.         mov    wp es:[di].Tail, dx
  130.         mov    wp es:[di].CurrentNode, dx
  131.  
  132.         mov    dx, wp ds:[si].Prev+2
  133.         mov    wp es:[di].Tail+2, dx
  134.         mov    wp es:[di].CurrentNode+2, dx
  135.  
  136.         or    dx, dx                ;List empty?
  137.         jz         LastGuy
  138.  
  139. ; If the list is not empty, we need to set the NEXT field of the new
  140. ; last node to NIL.
  141.  
  142.         les    di, es:[di].Tail
  143.         mov    wp es:[di].Next, 0
  144.         mov    wp es:[di].Next+2, 0
  145.         jmp    GoodRemove
  146.  
  147. ; If we just removed the last node from the list, set the head pointer
  148. ; to NIL (Tail is already NIL from above).
  149.  
  150.  
  151. LastGuy:    mov    wp es:[di].Head, dx
  152.         mov    wp es:[di].Head+2, dx
  153.  
  154.  
  155.  
  156.         endif
  157.  
  158. GoodRemove:    clc
  159.         mov    dx, ds
  160.  
  161. RemoveDone:    pop    di
  162.         pop    es
  163.         pop    ds
  164.         ret
  165.  
  166. sl_RemoveLast    endp
  167.  
  168. stdlib        ends
  169.         end
  170.